//
//  SYVerticalDetailTableHeaderViewDelegate.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2018/1/7.
//  Copyright © 2018年 LK-IOS. All rights reserved.
//

#import "YDVerticalDetailTableHeaderView.h"
#import "UIView+Multiple.h"
#import "MulTipleViewSelectedView.h"

@interface YDVerticalDetailTableHeaderView()<UIScrollViewDelegate , MulTipleViewSelectedViewDelegate>

@property (nonatomic , weak) UIScrollView *scrollerView;
@property (nonatomic, strong) NSArray *titles;

@property (nonatomic , weak) UIView *lineView;

@end



@implementation YDVerticalDetailTableHeaderView

- (NSArray *)titles
{
    if (!_titles) {
        _titles = @[@" 资讯 ", @" 简介 " ,@" 财务 "];
    }
    return _titles;
}

+ (instancetype)headerViewWithTableView:(UITableView *)tableView
{
    
    static NSString *verticalDetailTableHeaderView = @"YDVerticalDetailTableHeaderView";
    YDVerticalDetailTableHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:verticalDetailTableHeaderView];
    if (headerView == nil) {
        headerView = [[YDVerticalDetailTableHeaderView alloc] initWithReuseIdentifier:verticalDetailTableHeaderView];
    }
    return headerView;
}


-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        [self addScrollerView];
        [self addMultipleSelectedView];
        [self lineView];
    }
    return self;
}

/**
 滚动视图
 */
-(void)addScrollerView
{
    CGFloat scrollerH = 0.0f;
    scrollerH = isPhoneX ? rateX812(40) : rate750(40);
    UIScrollView *scrollerView = [[UIScrollView alloc] init];
    scrollerView.frame = CGRectMake(0, 0, LKScreenW, scrollerH);
    scrollerView.backgroundColor = [UIColor whiteColor];
    scrollerView.scrollsToTop = NO;
    scrollerView.bounces = YES;
    [self.contentView addSubview:scrollerView];
    scrollerView.delegate = self;
    self.scrollerView = scrollerView;
    scrollerView.showsHorizontalScrollIndicator = NO;
    scrollerView.showsVerticalScrollIndicator = NO;
    scrollerView.contentSize = CGSizeMake(self.titles.count * scrollerView.width, 0);
    scrollerView.pagingEnabled = YES;
}

/**
 多选择器
 */
-(void)addMultipleSelectedView
{
    MulTipleViewSelectedView * catergoryView = [MulTipleViewSelectedView new];
    catergoryView.edgeSpacing = rate375(30);
    catergoryView.titles = self.titles;
    catergoryView.scrollView = self.scrollerView;
    catergoryView.delegate = self;
    catergoryView.backgroundColor = [UIColor whiteColor];
    catergoryView.titleColor = [UIColor colorWithHexString:blueyGrey];
    catergoryView.titleSelectColor = [UIColor colorWithHexString:frenchBlue];
    catergoryView.titleColorChangeEable = YES;
    catergoryView.titleColorChangeGradually = YES;
    catergoryView.bottomLineEable = YES;
    catergoryView.titleFont = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
    catergoryView.bottomLineEable = NO;
    catergoryView.scrollWithAnimaitonWhenClicked = NO;
//    catergoryView.backEllipseEable = YES;
//    catergoryView.backEllipseColor = [UIColor colorWithHexString:frenchBlue];
    catergoryView.scaleEnable = YES;
    [self.contentView addSubview:catergoryView];
    [catergoryView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.scrollerView);
        make.left.right.equalTo(self);
    }];
}
/**
 监听多选择器点击
 */
- (void)catergoryView:(MulTipleViewSelectedView *)catergoryView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(verticalDetailTableHeaderView:didClickButtonTag:)]) {
        [self.delegate verticalDetailTableHeaderView:self didClickButtonTag:indexPath.item];
    }
}

-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = [UIColor colorWithHexString:mainGray];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.equalTo(@1);
        }];
        _lineView = lineView;
    }
    return _lineView;
}

@end
